#!/usr/bin/env python 
# -*- coding:utf-8 -*-

from dingtalkchatbot.chatbot import DingtalkChatbot


class DingTalkAPI(object):
    def __init__(self):
        self.mobiles = ['18xxxxxxx32']

    def dingtalk(self, msg, mobiles=None):
        # WebHook地址
        # TELDSOM自动运维群
        webhook = 'https://oapi.dingtalk.com/robot/send?access_token=?'
        # 初始化机器人小丁
        xiaoding = DingtalkChatbot(webhook)
        # Text消息@所有人
        # xiaoding.send_text(msg=msg, is_at_all=True)
        # Text消息@某人
        if mobiles:
            self.mobiles = mobiles
        xiaoding.send_markdown(title='MySQL集群节点异常', text=msg, is_at_all=False, at_mobiles=self.mobiles)
